import 'dart:io';
import 'package:path_provider/path_provider.dart';
import 'package:flutter/foundation.dart';

 Future<List<List>> csv (String url , {String filename = "csv" }) async {
    var client= new HttpClient();
    var req = await client.getUrl(Uri.parse(url));
    var res = await req.close();
    var bytes = await consolidateHttpClientResponseBytes(res);
    var address = (await getApplicationDocumentsDirectory()).path;
    File file = new File(address + filename);
    await file.writeAsBytes(bytes);
    String csv = await file.readAsString();
    await file.delete();
    List<String> rows = csv.split("\n");
    List<String> head = rows.removeAt(0).split(";");
    List<List<String>> data = new List();
    rows.forEach((row)=>data.add(row.split(';')));
    return [head,data];
  }
  
void main() async {

   var csvStr = await csv("http://sayagh.asnafhormozgan.ir/wp-content/tables/essentionals.csv");
  print(csvStr);

}